<html>
    <head>
    	<resource:dateChooser />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'usuario.label', default: 'Usuario')}" />
        <title>Fluxo de Caixa</title>
    </head>
    
    <body>
    <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}">Inicio</a></span>
            <span class="menuButton"><g:link class="create" action="create">Nova Movimentação Financeira</g:link></span>
    </div>
    <br>
    <h1>Fluxo de Caixa</h1>
    <br/>
    Selecione o intervalo de datas para consulta (deixe o campo em branco para a data corrente):
    <br><br>
    <g:form method="post">
    <table border="0" style="width: 600px;">
   	<tr>
   		
   		<td style="text-align: left; width: 100px;">Data Inicial:</td>
   	   	<td align="left"><richui:dateChooser name="data1" format="dd.MM.yyyy" firstDayOfWeek="Su"/></td>
   	   	
   	</tr>
   	
   	<tr>
   	
   		<td style="text-align: left; width: 100px;">Data Final:</td>
   		<td align="left"><richui:dateChooser name="data2" format="dd.MM.yyyy" firstDayOfWeek="Su"/></td>
   		
   	</tr>
   	
   	<tr>
   	
   		<td><span class="button"><g:actionSubmit id="pesquisar" name="pesquisar" value="Pesquisar" action="pesquisarMovimentosFinanceiros"/></span></td>
   	
   	</tr>
   	</table>
   	</g:form>
   	
   	<br><br>
   	
   	<g:set var="total" value="${ new BigDecimal(0).setScale(2, BigDecimal.ROUND_HALF_UP) }" />
   	<table border="0" style="width: 600px;">
   	<tr><th>Movimento Financeiro</th><th>Valor</th><th>Data</th></tr>
	<g:set var="index" value="${0 }" />
	<g:each in="${session.fluxoDeCaixaResult}" status="i" var="movimentoFinanceiro">
	<g:set var="ehImpar" value="${true}" />
   	<g:if test="${index % 2 == 0}"><g:set var="ehImpar" value="${false}" /></g:if>
   	
   	<tr
   	<g:if test="${ehImpar}"> bgcolor="#eeeeee"</g:if>
   	>
   		<g:set var="total" value="${ new BigDecimal(total + movimentoFinanceiro.valor).setScale(2, BigDecimal.ROUND_HALF_UP) }" />
   		<td>${movimentoFinanceiro.descricao}</td><td>${movimentoFinanceiro.valor}</td>
   		<td>${movimentoFinanceiro.data.date}.<g:if test="${movimentoFinanceiro.data.month < 10 }">0
   		</g:if>${movimentoFinanceiro.data.month}.${movimentoFinanceiro.data.year + 1900}</td>
   		</tr>
   	
   	<g:set var="index" value="${index + 1}" />
   	
   	</g:each>
   	<tr><th colspan="5" style="text-align: center;">&nbsp;</th></tr>
   	<tr style="heigh: 10pb;"></tr>
   
   	
   	</table>
   <h3>Total : ${total}</h3>	
   
    </body>
</html>
